﻿@using HotelManageSystem.Models
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutInventroy.cshtml";
}
<script type="text/javascript">

    function expandFirstRow(grid, row) {
        if (grid.$rows().index(row) == 0) {
            grid.expandRow(row);
        }
    }

    function products_onRowDataBound(p) {
        var grid = $(this).data('tGrid');
        expandFirstRow(grid, p.row);
    }

    function productDetails_onRowDataBound(p) {
        var grid = $(this).data('tGrid');
        expandFirstRow(grid, p.row);
    }
</script> 
@(Html.Telerik().Grid<WarehouseModel>()
     .Name("Warehouse")
     .Columns(columns=>
                  {
                      columns.Bound(w => w.Name).Title("仓库名");
                      columns.Bound(w => w.Employee).Title("管理员");
                  })
     .ClientEvents(events => events.OnRowDataBound("products_onRowDataBound"))
     .DetailView(productDetailView => productDetailView.ClientTemplate(
         Html.Telerik().Grid<ProductInInventory>()
                 .Name("Products_<#= WarehouseID #>")
             .Columns(columns =>
                          {
                              columns.Bound(p => p.Pid).Visible(true).Title("货品号");
                              columns.Bound(p => p.ProductName).Title("货品名").Width(100);
                              columns.Bound(p => p.Productcategory).Title("货品类别").Width(100);
                              columns.Bound(p => p.Productprovider).Title("提供商").Width(100);
                              columns.Bound(p => p.Countinventory).Title("库存 ").Width(150);
                          })
                 .ClientEvents(events => events.OnRowDataBound("productDetails_onRowDataBound"))
                     .DetailView(productDetail => productDetail.ClientTemplate(
                         Html.Telerik().Grid<ProductOfwarehouse>()
                                  .Name("ProductID_<#= Pid #>")
                                 .Columns(columms =>
                                              {
                                                  columms.Bound(p => p.ProductName).Title("货品名").Width(100);
                                                  columms.Bound(p => p.Inprice).Title("入库价格").Width(130);
                                                  columms.Bound(p => p.Countin).Title("入库数量").Width(130);
                                                  columms.Bound(p => p.Intime).Title("入库时间").Format("{0:d}").Width(150);
                                                  columms.Bound(p => p.Employeein).Title("入库负责人").Width(150);
                                                  columms.Bound(p => p.Outprice).Title("出库价格").Width(120);
                                                  columms.Bound(p => p.Countout).Title("出库数量").Width(120);
                                                  columms.Bound(p => p.Outtime).Title("出库时间").Format("{0:d}").Width(150);
                                                  columms.Bound(p => p.Employeeout).Title("出库负责人").Width(150);
                                              })

                             .DataBinding(dataBinding => dataBinding.Ajax()
                                     .Select("ProductDetailAjax", "Inventory", new { productID = "<#= Pid #>" }))
                                 .Pageable()
                                 .Sortable()
                                 .Filterable()
                                 .Selectable()
                                 .Scrollable()
                             .ToHtmlString()

                        ))
                                                                        
             .DataBinding(dataBinding => dataBinding.Ajax()
             .Select("ProductIninventory", "Inventory", new { warehouseID = "<#= WarehouseID #>" }))
             .Pageable()
             .Sortable()
             .Filterable()
             .Groupable()
             .ToHtmlString()
            ))
       
     .DataBinding(dataBinding => dataBinding.Ajax().Select("WarehouseHierarchyAjax", "Inventory"))
     .Pageable(paging => paging.PageSize(5))
     .Scrollable(scrolling => scrolling.Height(320))
     .Selectable()
     .Filterable()
     .Sortable()
     .Filterable()
     .Groupable()
     )
